#include "widget.h"
#include "ui_widget.h"
#include"QRect"
#include"QShortcut"
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    QShortcut*shortcut1=new QShortcut(this);//创建快捷键对象
    shortcut1->setKey(QKeySequence("-"));//加入快捷键-控制垂直滚动条减
    connect(shortcut1,&QShortcut::activated,this,&Widget::handersub);
    QShortcut*shortcut2=new QShortcut(this);
    shortcut2->setKey(QKeySequence("="));//加入快捷键=控制垂直滚动条加
    connect(shortcut2,&QShortcut::activated,this,&Widget::handeradd);
    ui->verticalSlider->setMinimum(100);
    ui->verticalSlider->setMaximum(1000);
    ui->verticalSlider->setSingleStep(100);
    ui->verticalSlider->setValue(600);//设置窗口初始值
    ui->horizontalSlider->setMinimum(100);
    ui->horizontalSlider->setMaximum(1200);
    ui->horizontalSlider->setSingleStep(100);
    ui->horizontalSlider->setValue(800);
}

Widget::~Widget()
{
    delete ui;
}
void Widget::handersub()
{
    int value=ui->verticalSlider->value();
    ui->verticalSlider->setValue(value-50);
    QRect rect=this->geometry();
    this->setGeometry(rect.x(),rect.y(),rect.width(),ui->verticalSlider->value());

}
void Widget::handeradd()
{
    int value=ui->verticalSlider->value();
    ui->verticalSlider->setValue(value+50);
    QRect rect=this->geometry();
    this->setGeometry(rect.x(),rect.y(),rect.width(),ui->verticalSlider->value());

}

void Widget::on_horizontalSlider_valueChanged(int value)
{
    QRect rect=this->geometry();
    this->setGeometry(rect.x(),rect.y(),value,rect.height());

}

void Widget::on_verticalSlider_valueChanged(int value)
{
    QRect rect=this->geometry();
    this->setGeometry(rect.x(),rect.y(),rect.width(),ui->verticalSlider->value());
}
